﻿using AntMovement.Core;
using AntMovement.Core.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.PCI9016
{
    public class Motion : IMotionBase
    {
        private int _index;
        public int Index => _index;
        private string _name;

        public string Name => _name;
        private long _status = -1;
        public Motion(string name, int index)
        {
            _name = name;
            _index = index;
        }

        public string Close()
        {
            _status = -1;
            PCI9016.p9016_close();
            return "ok";
        }

        public long GetStatus() => _status;

        public string Open()
        {
            int pCardCount = 0;
            int[] pBoardId = new int[16];
            int error = PCI9016.p9016_initial(ref pCardCount, pBoardId);
            if (error != 0)
            {
                return "Initialize PCI-9016 fail";
            }
            for (int i = 0; i < 6; i++)
            {
                PCI9016.p9016_set_pos(i, 0, 0);
            }
            _status = 0;
            return "ok";
        }
    }
}
